<style scoped>
</style>
<template>
	<div>
		<Form ref="formData" :model="formData" :rules="ruleInline" :label-width="80">
			<FormItem prop="id" label="用id">
				<Input type="text" disabled v-model="formData.id" placeholder="用id" />
			</FormItem>
			<FormItem prop="dbIp" label="账户">
				<Input type="text" v-model="formData.account" placeholder="账户" />
			</FormItem>
			<FormItem prop="ports" label="密码">
				<Input type="text" v-model="formData.password" placeholder="密码" />
			</FormItem>
			<FormItem prop="dbname" label="姓名">
				<Input type="text" v-model="formData.fullName" placeholder="姓名" />
			</FormItem>
			<FormItem prop="gender" label="用户状态">
				<RadioGroup v-model="formData.status">
					<Radio :label="0">禁用</Radio>
					<Radio :label="1">启用</Radio>
				</RadioGroup>
			</FormItem>
			<FormItem prop="gender" label="用户类型">
				<RadioGroup v-model="formData.userType">
					<Radio :label="0">普通用户</Radio>
					<Radio :label="1">管理员</Radio>
				</RadioGroup>
			</FormItem>

			<!-- <FormItem prop="password" label="密码">
				<Input type="password" v-model="formData.password" placeholder="xxx" />
			</FormItem> -->
			<FormItem>
				<Button style="float:right" type="success" @click="handleSubmit('formData')">保存</Button>
			</FormItem>
		</Form>
		<Spin fix v-show="addLoading"></Spin>
	</div>
</template>
<script>
	import moment from "moment";
	export default {
		name: "Add",
		props: {
			allDBList: Array,
			selected: Object
		},
		data() {
			return {
				batchList: [],
				addLoading: false,
				dbTestFlag: false,
				formData: {
					id: "",
					account: "",
					fullName: "",
					password: "",
					status: 1,
					userType: 0,
				},
				ruleInline: {
					account: [{
						required: true,
						message: "用户不能为空",
						trigger: "blur"
					}],
					password: [{
						required: true,
						message: "密码不能为空",
						trigger: "blur"
					}],
					fullName: [{
						required: true,
						message: "姓名不能为空",
						trigger: "blur"
					}]
				},
				selectArr: []
			};
		},
		methods: {
			//提交表单加校验表单
			handleSubmit(name) {
				this.$refs[name].validate(async valid => {
					if (valid) {
						this.addLoading = true;
						const result = await this.$api.saveOrUpdateEtlUser(this.formData);
						this.addLoading = false;
						if (result.code === 1) {
							this.$Message.success("保存成功!");
							this.$emit("fun");
						} else {
							this.$Message.error(result.errMsg);
						}
					}
				});
			}


		},
		mounted() {
			console.log(this.selected);
			if(this.selected != null && this.selected.id != null){
				this.formData = this.selected;
			}
		}
	};
</script>
